﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Cfg.MappingSchema;
using System.CodeDom;

namespace MVCGen.Generators.Entity {
	public class HbmArrayPropertyGenerator : ICodeTypeMemberGenerator {
		private HbmArray array;
		private ICodeTypeMemberGenerator elementGenerator;

		public HbmArrayPropertyGenerator(HbmArray array) {
			this.array = array;
			if (array.Item1 is HbmElement)
				this.elementGenerator = new HbmElementPropertyGenerator(array.name, array.Item1 as HbmElement);
			else if (array.Item1 is HbmManyToMany)
				this.elementGenerator = new HbmManyToManyPropertyGenerator(array.name, array.Item1 as HbmManyToMany);
			else if (array.Item1 is HbmCompositeElement)
				this.elementGenerator = new HbmCompositeElementPropertyGenerator(array.name, array.Item1 as HbmCompositeElement);
			else if (array.Item1 is HbmManyToAny)
				this.elementGenerator = new HbmManyToAnyPropertyGenerator(array.name, array.Item1 as HbmManyToAny);
			else if (array.Item1 is HbmOneToMany)
				this.elementGenerator = new HbmOneToManyPropertyGenerator(array.name, array.Item1 as HbmOneToMany);
			else
				throw new ArgumentException(String.Format("Unsupported Array item {0}", array.Item1.GetType().Name));
		}

		public CodeTypeMember Generate() {
			return elementGenerator.Generate();
		}
	}
}
